package com.sloth.controller;

import com.sloth.service.ProductService;
import com.sloth.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lai
 * @time 2021/10/6 9:47
 */
@Controller
public class ProductController {

    @Autowired
    private ProductService productService;



    // 首页加载商品数据，品牌中显示
    @GetMapping("/product/generalMerchandise")
    @ResponseBody
    public List<ServerResponse> generalMerchandise(){

        List<ServerResponse> serverResponseList = new ArrayList<>();

        ServerResponse serverResponse = productService.getProductAll();

        ServerResponse productRecommendation = productService.getProductRecommendation();

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("serverResponse",serverResponse);
        modelAndView.addObject("productRecommendation",productRecommendation);
        modelAndView.setViewName("product/generalMerchandise");
        serverResponseList.add(serverResponse);
        serverResponseList.add(productRecommendation);
        for (ServerResponse serverResponse1 : serverResponseList){
            System.out.println(serverResponse1);
        }

        return serverResponseList;
    }

    /*// 首页加载推荐商品数据，推荐显示
    @GetMapping("/product/generalMerchandise")
    public ModelAndView generalMerchandiseProduct(){

        ServerResponse serverResponse = productService.getProductAll();

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("serverResponse",serverResponse);
        modelAndView.setViewName("product/generalMerchandise");

        System.out.println("哈哈");

        return modelAndView;
    }*/

    @GetMapping("/products/conditions")
    @ResponseBody
    public ServerResponse getByConditions(String proName,  String other1,String other2 ,Double minPrice, Double maxPrice, Double proPrice,Integer pageNum){
        if(pageNum == null)
            pageNum = 1;


        ServerResponse serverResponse = productService.getByConditions(proName,other1,other2,minPrice,maxPrice,proPrice,pageNum);
        System.out.println("到这儿了");
        return serverResponse;
    }

}